<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.io.IOException"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.sci99.ex.model.*"%>
<%@ page import="com.sci99.ex.util.*"%>
<%@ page import="org.apache.log4j.Logger"%>
<%@ page import="org.apache.commons.lang3.math.NumberUtils"%>
<%@ page
	import="org.springframework.security.core.userdetails.UserDetails"%>
<%@ page
	import="org.springframework.security.core.context.SecurityContextHolder"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
	Logger log = Logger.getLogger(this.getClass());
	Employee user = UserUtil.getUser();
	request.setAttribute("user", user);

	//log.error(user.getId());
	String sql = "select a.name as category_name,c.* from course as c "
                +"join category a on c.category_id = a.id "
                +"where c.id in (select course_id from employee_course where employee_id = ?)";
	List r = new ArrayList();
	Connection con = null;
	ResultSet rs = null;
    try {
		con = JDBCUtil.getCon();
		PreparedStatement ps = con.prepareStatement(sql,
				java.sql.ResultSet.TYPE_FORWARD_ONLY,
				java.sql.ResultSet.CONCUR_READ_ONLY);
		ps.setLong(1, user.getId());
		rs = ps.executeQuery();
		while (rs.next()) {
			Map m = new HashMap(8, 1);
			m.put("id", rs.getLong("id"));
			m.put("name", rs.getString("name"));
			m.put("lecturer", rs.getString("lecturer"));
			m.put("category_name", rs.getString("category_name"));
			m.put("period", rs.getString("period"));
			m.put("video_url", VideoUtil.getVideoURL(rs.getLong("id"),rs.getString("video_url")));
			r.add(m);
		}
	} catch (SQLException se) {
		log.error("", se);
	} finally {
		try {
			rs.close();
			con.close();
		} catch (Exception inr) {
			log.error("", inr);
		}
	}
    
	request.setAttribute("rs", r);
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>课程管理页</title>
<link href="styles/base.css" rel="stylesheet" type="text/css" />
<link href="styles/common.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="public/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
    function removeCourse(cid){
        $.ajax({
            type: 'POST',
            url: 'opt',
            data: { 'act':'removeCourse','course':cid },
            success: function(data, textStatus, jqXHR){
                if(data.success){
                    alert('删除成功');
                    location.reload();
                }else{
                    alert('删除失败');
                }
            },
            dataType:'json'
        });
    }
</script>
</head>
<body>
    <form id="form1">
    <div class="main_out">
        <div class="main_top">
            <a href=""></a> <span>人力资源培训服务热线：6091073 7071868</span>
        </div>
        <div class="clear"></div>
        <div class="nav">
            <ul class="nav_l">
                <li><a href="index.jsp">首&nbsp;&nbsp;页</a></li>
                <li><a href="manage.jsp" style="background:#f3f3f3; color:#0186d5!important">课程管理</a></li>
                <!--li><a href="search.jsp">课程搜索</a></li -->
				<!--li><a href="add.jsp">课程添加</a></li -->
				<!--li><a href="video.jsp">视频播放</a></li -->
				<!--li><a href="login.jsp">登录页</a></li -->
            </ul>
            <div class="nav_r">
                <a href="j_spring_security_logout">退出登录</a>
            </div>
        </div>
    </div>
    <div class="main">
      <div class="head2 mt">
        <span><a href="#" class="h_h">已选课程</a><a href="history.jsp">历史课程</a></span>
        <h2><a href="add.jsp"></a></h2>
      </div>
      <div class="content">
        <table cellspacing="0" class="tab_my">
          <thead>
                <tr>
                    <th>[课程分类]</th>
                    <th>[课程名称]</th>
                    <th width="55">[讲师]</th>
                    <th width="55">[进度]</th>
                    <th width="25">&nbsp;</th>
                    <th width="40">&nbsp;</th>
                </tr>
                <c:forEach items="${rs}" var="mp">
                    <tr>
                        <td><c:out value="${mp.category_name}" /></td>
                        <td><c:out value="${mp.name}" /></td>
						<td><c:out value="${mp.lecturer}" /></td>
                        <td>&nbsp;</td>
                        <td><a href="${mp.video_url}"></a></td>
                        <th><a href="javascript:removeCourse(${mp.id})">删除</a></th>
                    </tr>
                </c:forEach>
          </thead>
        </table>
      </div>
      <div class="head mt">
        <span>您可能感兴趣的课程</span>
      </div>
      <div class="content">
        <table cellspacing="0" class="tab_my">
          <thead>
          <tr>
            <th>[课程分类]</th>
            <th>[课程名称]</th>
            <th width="55">[讲师]</th>
            <th width="55">[课时]</th>
            <th width="25">&nbsp;</th>
            <th width="40">&nbsp;</th>
          </tr>
          </thead>
          <tr>
            <td>人力资源类</td>
            <td>企业招聘通常遇到的难题与招聘渠道的开发</td>
            <td>邵正江</td>
            <th>10</th>
            <td><a href="#"></a></td>
            <th>&nbsp;</th>
          </tr>
          <tr>
            <td>客服产品知识类</td>
            <td>岗位素质模型在招聘选才中的应用</td>
            <td>刘晓辉</td>
            <th>8</th>
            <td><a href="#"></a></td>
            <th>&nbsp;</th>
          </tr>
        </table>
      </div>
    </div>
    <div class="foot_out mt">
      <div class="foot">Copyright &copy; 2004-2012 SCI99 Inc. All rights reserved.</div>
    </div>
    </form>
</body>
</html>
